#define _CRT_SECURE_NO_WARNINGS 1

#include "SList.h"

Listnode* removeElement(Listnode* phead, Listdatatype x)
{
	Listnode* remove, * relast;
	remove = relast = NULL;

	if (phead == NULL)
		return NULL;
	Listnode* pcur = phead;
	while (pcur)
	{
		if (pcur->data == x)
		{
			;
		}
		else
		{
			if (remove == NULL)
			{
				remove = relast = pcur;
			}
			else
			{
				relast->next = pcur;
				relast = pcur;
			}
		}
		pcur = pcur->next;
	}
	if (relast)
		relast->next = NULL;

	return remove;
}

int main()
{
	Listnode* phead = NULL;
	Listpushback(&phead, 1);
	Listpushback(&phead, 2);
	Listpushback(&phead, 6);
	Listpushback(&phead, 3);
	Listpushback(&phead, 4);
	Listpushback(&phead, 5);
	Listpushback(&phead, 6);
	removeElement(phead, 6);
	Listprint(phead);

	Listnode* remove = removeElement(phead, 6);
	return 0;
}